package com.huizu.project.apiController;

import com.huizu.common.annotation.Anonymous;
import com.huizu.common.annotation.Log;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.core.page.TableDataInfo;
import com.huizu.common.enums.BusinessType;
import com.huizu.common.utils.poi.ExcelUtil;
import com.huizu.project.config.TerAspect;
import com.huizu.project.domain.ProUserDc;
import com.huizu.project.service.IProUserDcService;
import com.huizu.project.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 督促信息Controller
 * 
 * @author zhangmx
 * @date 2024-06-05
 */
@Anonymous
@RestController
@RequestMapping("/api/prouserdc")
public class ApiProUserDcController extends BaseController
{
    @Autowired
    private IProUserDcService proUserDcService;

    /**
     * 查询督促信息列表
     */
    @PostMapping("/list")
    public TableDataInfo list(ProUserDc proUserDc, HttpServletRequest request)
    {
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proUserDc.setUserId(userId);
        proUserDc.setBeUserId(userId);
        List<ProUserDc> list = proUserDcService.selectProUserDcListApi(proUserDc);
        return getDataTable(list);
    }

    /**
     * 查询督促信息列表
     */
    @PostMapping("/listTer")
    public TableDataInfo listTer(ProUserDc proUserDc, HttpServletRequest request)
    {
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proUserDc.setUserId(userId);
        List<ProUserDc> list = proUserDcService.selectDcListTerApi(proUserDc);
        return getDataTable(list);
    }


    /**
     * 获取督促信息详细信息
     */
    @PostMapping(value = "/getById")
    public AjaxResult getInfo(@RequestBody ProUserDc proUserDc)
    {
        String id = proUserDc.getId();
        return success(proUserDcService.selectProUserDcById(id));
    }

    /**
     * 确认督促
     * @param proUserDc
     * @param request
     * @return
     */
    @PostMapping("/subDc")
    public AjaxResult subSt(@RequestBody ProUserDc proUserDc,HttpServletRequest request){
//        String token = request.getHeader(TokenUtils.getAppTokenHeader());
//        String userId = TokenUtils.parseToken(token);//获取用户id
//        proUserDc.setUserId(userId);
        return proUserDcService.subSt(proUserDc);
    }

    /**
     * 新增督促信息
     */
    @TerAspect
    @PostMapping("/dcSt")
    public AjaxResult dcSt(@RequestBody ProUserDc proUserDc,HttpServletRequest request)
    {
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proUserDc.setTerId(userId);
        return proUserDcService.dcSt(proUserDc);
    }


    @TerAspect
    @PostMapping("/listLsDc")
    public TableDataInfo listLsDc(ProUserDc proUserDc,HttpServletRequest request){
        String token = request.getHeader(TokenUtils.getAppTokenHeader());
        String userId = TokenUtils.parseToken(token);//获取用户id
        proUserDc.setTerId(userId);
        proUserDc.setBeUserId(userId);
        return getDataTable(proUserDcService.selectProUserDcListApi(proUserDc));
    }

    /**
     * 修改督促信息
     */
    @PreAuthorize("@ss.hasPermi('project:prouserdc:edit')")
    @Log(title = "督促信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProUserDc proUserDc)
    {
        return toAjax(proUserDcService.updateProUserDc(proUserDc));
    }

    /**
     * 删除督促信息
     */
    @PreAuthorize("@ss.hasPermi('project:prouserdc:remove')")
    @Log(title = "督促信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(proUserDcService.deleteProUserDcByIds(ids));
    }
}
